/**
 * 像这种，类名和对象名同名的情况，该类称为伴生类(companion class)，该对象称为伴生对象(companion object)
 */
package net.scala.chapter3.c

import com.mongodb.{DB => MongoDB}

import scala.collection.convert.Wrappers._

class DB private(val underlying: MongoDB) {
  private def collection(name: String) = underlying.getCollection(name)

  def localeAwareReadOnlyCollection(name: String) =
      new DBCollection(collection(name)) with LocaleAware with Memoizer
  def readOnlyCollection(name: String) =
      new DBCollection(collection(name)) with Memoizer
  def administrableCollection(name: String) =
      new DBCollection(collection(name)) with Administrable with Memoizer
  def updatableCollection(name: String) =
      new DBCollection(collection(name)) with Updatable with Memoizer
  def collectionNames =  for(name <- new JSetWrapper(underlying.getCollectionNames)) yield name
}

object DB {
  def apply(underlying: MongoDB) = new DB(underlying)
}
